<?php
class Company extends Zend_Db_Table{
    	protected $_name ="companys";
	protected $_primary = 'company_id';


        public function getTopCompanys(){
          $select = $this->select();
          $select->limit('10');
          $select->order('company_id desc');
          return $this->fetchAll($select)->toArray();
    }

public function get($company_id){
    $arrP=$this->fetchAll("pid=$company_id")->toArray();
    for($i=0;$i<count($arrP);$i++){
                            $data['company_id']=$arrP[$i]['company_id'];
                            $data['name']=$arrP[$i]['name'];
                            $data[]=$this->get($arrP[$i]['company_id']);
                        }
    return $data;
}
    // 查询所有company
    public function getAllCompanys($page,$perpage,$search_name,$search_city){
          $where = "1=1";
          if($search_name!=""){
              $where.=" and name like '%$search_name%'";
          }else if($search_city!=""){
              $where.=" and city like '%$search_city%'";
          }

          $select = $this->select();
          $select->where($where);
          if($page!=""){
          $select->limitPage($page,$perpage);
          }
          $select->order('company_id desc');
          return $this->fetchAll($select)->toArray();
    }
    
    // 查询所有company
    public function getAllCompanysexcel(){
          $where = "1=1";

          $select = $this->select();
          $select->where($where);

          $select->order('company_id asc');
          return $this->fetchAll($select)->toArray();
    }

     //根据company_id 查询company
    public function getCompanyBycompany_id($company_id){
          $select = $this->select();
          $select->where("company_id=".$company_id);
          return $this->fetchAll($select)->toArray();
    }
	
	//根据company_name 查询company
	public function getCompanyBycompany_name($company_name){
		$select = $this->select();
		$select->where("name='".$company_name."'");
		return $this->fetchAll($select)->toArray();
    }

 //更新company
    public function updatecompanyBycompany_id($array,$company_id){

		$db = $this->getAdapter();
		$where=$db->quoteInto('company_id = ?', $company_id);
		$this->update($array, $where);
	}
//删除company
     public function delcompanyBycompany_id($company_id){
          $where = 'company_id = '. $company_id;
         $this->delete($where);
         return true;
    }
}
?>
